package com.ch.shopping.dao;

import com.ch.shopping.mapper.UserMapper;
import com.ch.shopping.pojo.User;
import com.ch.shopping.pojo.UserExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author AuthorName
 * @create 2020-04-13 15:39
 */
@Repository
public class UserDao {
    @Autowired
    private UserMapper userMapper;
    /**
     * 根据id进行查询用户
     */
    public User queryUserById(Integer id){
        return userMapper.selectByPrimaryKey(id);
    }
    /**
     * 根据用户名查找密码
     */
    public String queryPwdByName(String name){
        UserExample userExample = new UserExample();
        UserExample.Criteria criteria = userExample.createCriteria();
        criteria.andUsernameEqualTo(name);
        List<User> users = userMapper.selectByExample(userExample);
        // 2.增强的for循环
        String pwd;
        for (User str : users) {
            pwd = str.getPwd();
        }
       return "12";
    }
}
